import { createYoga, createSchema } from "graphql-yoga";
import { createServer } from "http";
import { typeDefs } from "./graphql/generated/typeDefs.generated";
import { resolvers } from "./graphql/generated/resolvers.generated";
import { useJWT } from "@graphql-yoga/plugin-jwt";
import { useAuth } from "./plugins/auth";

require('dotenv').config()
const signingKey = process.env.JWT_SECRET ?? "secret.key";
const issuer = process.env.JWT_ISSUER;

const yoga = createYoga({
  schema: createSchema({ typeDefs, resolvers }),
  plugins: [
    useJWT({
      issuer: issuer,
      signingKey: signingKey,
      algorithms: ['HS256']
      /*
      getToken: ({ request }) => {
        console.log(request.headers.get("authorization"))
        return request.headers.get("authorization")
      },
      */
    }),
    //useAuth()
  ],
});
const server = createServer(yoga);
server.listen(3000);
